package com.wsjzzcbq.qianyuan.common.config;

import com.wsjzzcbq.qianyuan.common.interceptor.LoginCheckInterceptor;
import com.wsjzzcbq.qianyuan.common.interceptor.UploadFileInterceptor;
import com.wsjzzcbq.qianyuan.common.interceptor.WeiXinInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Bean
    public WeiXinInterceptor weiXinInterceptor() {
        return new WeiXinInterceptor();
    }

    @Bean
    public LoginCheckInterceptor loginCheckInterceptor() {
        return new LoginCheckInterceptor();
    }

    @Bean
    public UploadFileInterceptor uploadFileInterceptor() {
        return new UploadFileInterceptor();
    }

    /**
     * 认证访问控制
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //登录验证拦截
        registry.addInterceptor(loginCheckInterceptor()).
                excludePathPatterns(
                        "/open/**",
                        "/sys/file/upload",
                        "/sys/user/login",
                        "/favicon.ico",
                        "/error",
                        "/static/**",
                        "/index.html",
                        //vue打包后刷新页面过滤/login请求
                        "/login",
                        "/"
                );
        //文件上传拦截
        registry.addInterceptor(uploadFileInterceptor()).addPathPatterns("/sys/file/upload");
        //微信小程序拦截
        registry.addInterceptor(weiXinInterceptor()).
                addPathPatterns("/weixin/**");
    }


}
